package org.sxf.app.sign.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.sxf.app.sign.R;
import org.sxf.app.sign.activity.SplashActivity;
import org.sxf.app.sign.biz.BaseBiz;
import org.sxf.app.sign.biz.LogoutBiz;
import org.sxf.app.sign.constants.Constants;
import org.sxf.app.sign.data.DataCacheSingleton;
import org.sxf.app.sign.utils.ConfigFileUtilsSingleton;
import org.sxf.app.sign.widgt.T;

import java.util.ArrayList;


public class MyFragment extends BaseFragment implements View.OnClickListener, BaseBiz.OnBizCallBackListener {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    private LogoutBiz mLogoutBiz;


    public static MyFragment newInstance(String param1, String param2) {
        MyFragment fragment = new MyFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    public MyFragment() {
        // Required empty public constructor
    }


    private void gotoLoginView(){
        Intent intent = new Intent(getActivity(), SplashActivity.class);
        intent.putExtra("s_logout", "");
        getActivity().startActivity(intent);
        getActivity().overridePendingTransition(R.anim.act_null, R.anim.act_fade_out);
        getActivity().finish();

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my, container, false);

        view.findViewById(R.id.logout).setOnClickListener(this);

        mLogoutBiz = new LogoutBiz(getActivity(), this);

        return view;
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){

            case R.id.logout:{
                popLoadingDialog(getString(R.string.select_loading));

                mLogoutBiz.logout();
                break;
            }




        }
    }

    @Override
    public void onBizResult(int biz, Object result) {
        switch (biz){

            case LogoutBiz.BIZ_LOGOUT_SUCCESS:
                dismissLoadingDialog();
                gotoLoginView();
                break;
            case LogoutBiz.BIZ_LOGOUT_FAIL:
                dismissLoadingDialog();
                T.s(getActivity(), getString(R.string.logout_fail));
                break;
        }
    }

    @Override
    public void onBizError(int biz, Object result) {
        switch (biz){
            case LogoutBiz.ERROR_LOGOUT_NET_ERROR:
                dismissLoadingDialog();
                T.s(getActivity(), getString(R.string.net_error));
                break;
        }
    }
}
